#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2025/1/23 11:17
# @Author : ZhengQL

from playwright.sync_api import Page


class RegisterPage:
    def __init__(self, page):
        self.page = page
        # 注册页面
        self.register_username = page.get_by_placeholder('请输入用户名')
        self.register_password = page.get_by_placeholder('请输入密码')
        self.locator_register_btn = page.get_by_role("button",name='立即注册')
        # self.locator_login_btn = page.locator(text='已有账号？点这登录')

        # 账号输入框提示语
        self.locator_register_username_tip1 = page.locator('[data-fv-validator="stringLength"][data-fv-for="username"]')
        self.locator_register_username_tip2 = page.locator('[data-fv-validator="stringLength"][data-fv-for="username"]')
        self.locator_register_password_tip3 = page.locator('[data-fv-validator="regexp"][data-fv-for="password"]')

        # 密码输入框提示语
        self.locator_register_password_tip1 = page.locator('[data-fv-validator="notEmpty"][data-fv-for="password"]')
        self.locator_register_password_tip2 = page.locator('[data-fv-validator="stringLength"][data-fv-for="password"]')
        self.locator_register_password_tip3 = page.locator('[data-fv-validator="regexp"][data-fv-for="password"]')

    # 封装页面操作方法
    def navigate(self):
        self.page.goto('http://47.116.12.183/register.html')
    def fill_register_username(self, username):
        self.register_username.fill(username)

    def fill_register_password(self, password):
        self.register_password.fill(password)

    def click_register_btn(self):
        self.locator_register_btn.click()


    # 封装一个注册方法
    def register(self, username, password):
        self.fill_register_username(username)
        self.fill_register_password(password)
        self.click_register_btn()



